﻿@model DoAnWebsite.Models.Comment
@using CaptchaMvc.HtmlHelpers
@using System.Globalization

<div id="Comment" class="clearfix">
    @if (ViewBag.OnePageOfComment.PageCount!=0)
    {
        <fieldset class="showComment"> 
        <legend>Các bình luận</legend>
        @foreach (var item in ViewBag.OnePageOfComment)
        {
            <div class="comment clearfix" id="cm-@item.CommentId">
                <div class="cm-info">
                    <div class="AuthorName">
                        <span style="font-weight: normal; color: deepskyblue">Gửi bởi:</span> @item.AuthorName
                    </div>
                    <div class="emailComment">Email: @item.Email</div>
                    <div class="dateComment">@item.Date</div> 
                    @if (Request.IsAuthenticated)
                    {
                        <div>
                            @Ajax.ActionLink("Xoa Comment", "DeleteComment", "Share", new { id = item.CommentId }, new AjaxOptions
                                                                                                 {
                                                                                                     Confirm = "Bạn có chắc chấn muốn xóa bài này?",
                                                                                                     UpdateTargetId = "cm-"+item.CommentId
                                                                                                 })
                        </div>
                    }
                </div>  
                <div class="cm-main">
                    <div class="titleComment">@item.Title</div>
                    <div class="contentComment">@item.Content</div>
                </div>  
            </div>
        }

        <div>
            <div class="btn-page">
                @Ajax.ActionLink("Đầu", "Index", new { page = 1 }, new AjaxOptions { UpdateTargetId = "Comment" })
                @Ajax.ActionLink("<", "Index", new { page = ViewBag.OnePageOfComment.PageNumber - 1 }, new AjaxOptions { UpdateTargetId = "Comment" })
                @for (int i = 1; i <= ViewBag.OnePageOfComment.PageCount; i++)
                {
                    var page = i.ToString(CultureInfo.InvariantCulture);
                    @Ajax.ActionLink(page, "Index", new { page = i }, new AjaxOptions { UpdateTargetId = "Comment" }, new { @id = "cmpage" + page })
                }
                @Ajax.ActionLink(">", "Index", new { page = ViewBag.OnePageOfComment.PageNumber + 1 }, new AjaxOptions { UpdateTargetId = "Comment" })
                @Ajax.ActionLink("Cuối", "Index", new { page = ViewBag.OnePageOfComment.PageCount }, new AjaxOptions { UpdateTargetId = "Comment" })
            </div>
        </div>
    </fieldset>
    }
    
    <script>
        $(document).ready(function () {
            var page = @ViewBag.pageNumber;
            var id = "cmpage" + page;
            $(".btn-page a").removeClass("active");
            $('#' + id).addClass('cmpageActive');
        });
    </script>
    
    <div>
        @using (Ajax.BeginForm("CreateComment1", "Share", new AjaxOptions()
        {
            UpdateTargetId = "Comment",
            HttpMethod = "Post",
            //OnComplete = "createCM();",
            OnSuccess = "createCM();"
        }))
        {       
            @Html.ValidationSummary(true)
            <fieldset class="createComment">
                <legend>Gửi bình luận</legend>
                <div class="editor-label ">
                    <span>Họ tên</span>
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.AuthorName)
                    @Html.ValidationMessageFor(model => model.AuthorName)
                </div>
                <div class="editor-label">
                    <span>Email</span>
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Email)
                    @Html.ValidationMessageFor(model => model.Email)
                </div>
                <div class="editor-label">
                    <span>Tiêu đề</span>
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Title)
                    @Html.ValidationMessageFor(model => model.Title)
                </div>
                <div class="editor-label">
                    <span>Nội dung</span>
                </div>
                <div class="editor-field">
                    @Html.EditorFor(model => model.Content)
                    @Html.ValidationMessageFor(model => model.Content)
                </div>
                <div class="capcha">
                    @Html.Captcha("Refresh", "Input", 5, "Is required field.")
                    @ViewBag.ErrorMessage
                </div>
                <input type="hidden" name="MaBaiViet" value="@ViewBag.Id" />
                <p class="btncomment">
                    <input type="submit" value="Gửi Comment" class="btn btn-success btn-large" />
                </p>
            </fieldset>
        }
    </div>
</div>
